package com.fenghongzhang.day005;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.SeekBar;

import androidx.appcompat.app.AppCompatActivity;

import java.util.Timer;
import java.util.TimerTask;

public class MainActivity extends AppCompatActivity {

    private static final String TAG = "MainActivity";
    private Button button;
    private ProgressBar bar;
    private  int i = 0;
    private SeekBar seekBar;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

         button = findViewById(R.id.send);
         bar = findViewById(R.id.pg1);

         seekBar = findViewById(R.id.seek);
         seekBar.setMax(100);
//         seekBar.setProgress(10);
//         seekBar.setSecondaryProgress(20);



         //定时器
        final Timer timer = new Timer(); //闹钟
        /**
         * 1,任务
         * 2,延迟 60  0
         * 3,价格时间. 毫秒值
         */
        timer.schedule(new TimerTask() {  //设置了一个闹铃
            @Override
            public void run() {
                Log.i(TAG, "run: haha");
                i+=1;
                seekBar.setProgress(i);
                if(i >= seekBar.getMax()){
                    timer.cancel();
                }
            }
        },0,1000);

        //停止计时器
        //timer.cancel();


        seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
             /**
              *
              * @param seekBar
              * @param progress  当前的进度
              * @param fromUser  是否是用户拖动
              */
             @Override
             public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
//                 Toast.makeText(MainActivity.this, progress+"", Toast.LENGTH_SHORT).show();
                 /**
                  * TAG 标签
                  */
                 Log.i(TAG, "onProgressChanged: "+progress);

                 if(fromUser){

                 }

             }

             //**开始拖动
             @Override
             public void onStartTrackingTouch(SeekBar seekBar) {
             }

             //停止拖动
             @Override
             public void onStopTrackingTouch(SeekBar seekBar) {

             }
         });

    }

    public void send(View view) {
        String name = "xiaoming";
        String string = button.getText().toString();
        Intent intent = new Intent(this, LoginActivity.class);
        intent.putExtra("name",name);
        intent.putExtra("va",string);
        startActivity(intent);
    }

    public void add(View view) {
        //更改进度条的值 ,整数是增加,负数是减少
        //bar.incrementProgressBy(10);
        i+=10;
        bar.setProgress(i);
    }

    public void sub(View view) {
        //bar.incrementProgressBy(-10);
    }
}
